package com.wyz.demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadLocalWithThreadPool {
    private static final ThreadLocal<String> threadLocal = new ThreadLocal<>();

    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(2);

        threadLocal.set("Parent Thread Value");

        // 获取父线程的 ThreadLocal 值
        String parentValue = threadLocal.get();

        // 提交任务到线程池
        executor.submit(() -> {
            threadLocal.set(parentValue); // 设置父线程的值
            System.out.println("Child Thread: " + threadLocal.get());
        });

        executor.shutdown();
    }
}